﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using smp.ButterflyCakes.Models.Data;

namespace smp.ButterflyCakes.Models.FormModels.Order
{
    public class ComponentPreserveModel
    {
        [Required]
        public Guid OrderId { get; set; }
        [Required]
        public Guid ComponentId { get; set; }

        public bool IsPreserveValid { get; private set; }
        public Guid? ButtercreamId { get; set; }
        public Guid? GanacheId { get; set; }
        public Guid? PreserveId { get; set; }
        public SelectItem SelectPreserve { get; private set; }

        public void AddPreserves(List<FillingItem> items, List<IncompatibleItem> incompatibleWithFilling, List<IncompatibleItem> incompatibleWithCake)
        {
            SelectPreserve = new SelectItem("PreserveId", true);
            foreach(var item in items)
            {
                if(incompatibleWithFilling.Any(x => x.Id == item.Id))
                {
                    SelectPreserve.AddOption(new SelectOption(item.Name, item.Id, true, "Incompatible with filling"));
                }
                else if(incompatibleWithCake.Any(x => x.Id == item.Id))
                {
                    SelectPreserve.AddOption(new SelectOption(item.Name, item.Id, true, "Incompatible with cake flavour"));
                }
                else
                {
                    SelectPreserve.AddOption(new SelectOption(item.Name, item.Id));
                }
            }
            IsPreserveValid = SelectPreserve.Options.Any(x => !x.IsDisabled);
        }
    }
}
